package com.alibaba.aone.casestudy.module.screen;

import static com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.aone.casestudy.common.WebConstant;
import com.alibaba.aone.casestudy.common.entity.AoneDepart;
import com.alibaba.aone.casestudy.service.AoneUserService;
import com.alibaba.aone.casestudy.service.FailureService;
import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.TurbineRunDataInternal;

/**
 * 类FailureDetailAdd.java的实现描述：TODO 类实现描述 
 * @author yongchun.chengyc 2011-5-6 上午09:38:25
 */
public class FailureDetailAdd {
	@Autowired
	private FailureService failureService;
	@Autowired
	private HttpServletRequest request;
	@Autowired
	private AoneUserService userService;
	
	public void execute(Context context){
		//自动生成编号
		Date now = new Date();
		SimpleDateFormat format1 = new SimpleDateFormat("yyyy");
		String year = format1.format(now);
		long auto = failureService.setFailureNumber()+1;
		String number = "F"+year+auto;
		context.put("number", number);
		
		
		TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
		String cookie = rundata.getCookies().getString(
				WebConstant.AONE_COOKIE_LOGIN_NAME);
		context.put("loginName", cookie);

		List<AoneDepart> departList = userService.getAllDepart();
		

		context.put("departList", departList);
		
	}

}
